import * as mixins from '@/utils/mixins';
import * as filters from '@/utils/filters';
import * as constants from "@/utils/constants";
import * as functions from '@/utils/functions';
import * as directives from "@/utils/directives";
const componentsContext = require.context('@/components/global/', true, /\.vue$/);
export default {
	install(Vue) {

		//全局组件
		componentsContext.keys().forEach((component) => {
			const componentsConfig = componentsContext(component)
			const componentSelf = componentsConfig.default || componentsConfig
			if (componentSelf && componentSelf.name) {
				Vue.component(componentSelf.name, componentSelf)
			}
		})

		//全局常量
		Object.keys(constants).forEach(key => {
			Vue.prototype[key] = constants[key];
		})

		//全局过滤器
		Object.keys(filters).forEach(key => {
			Vue.filter(key, filters[key])
		})

		//全局事件
		Object.keys(functions).forEach(key => {
			Vue.prototype[key] = functions[key]
		})

		//定义全局指令
		Object.keys(directives).forEach(key => {
			Vue.directive(key, directives[key]);
		})

		//定义全局混入
		Object.keys(mixins).forEach(key => {
			Vue.mixin(mixins[key]);
		})
	}
};